Skip to content

fix(tm2/amino): preserve nil_elements in genproto2#5569

Closed
D4ryl00 wants to merge 2 commits intognolang:masterfrom
D4ryl00:fix/amino-nil-elements-commit
Closed

fix(tm2/amino): preserve nil_elements in genproto2#5569
D4ryl00 wants to merge 2 commits intognolang:masterfrom
D4ryl00:fix/amino-nil-elements-commit

Conversation

@D4ryl00
Copy link
Copy Markdown
Contributor

@D4ryl00 D4ryl00 commented Apr 22, 2026

Summary

Fix a genproto2 regression introduced by #5282 e8aac7575f (feat(amino): add genproto2).

After regenerating pb3_gen.go from master, gnoland consensus started failing deterministically because types.Commit.Precommits uses amino:"nil_elements", and the generated genproto2 decoder did not preserve positional nil entries in unpacked pointer lists.

In the failing path:

  • a commit with one missing validator precommit was marshaled with a zero-length ByteLength entry for that validator
  • genproto2 unmarshal reconstructed that entry incorrectly
  • the next proposal’s LastCommit then failed block validation with wrong LastCommit
  • the proposer rejected its own block and the chain wedged

Root Cause

Marshal was already correct: for unpacked pointer lists with amino:"nil_elements", genproto2 encodes a nil element as an empty ByteLength value (0x00), matching the reflect codec.

The bug was in generated unmarshal: it did not turn that empty entry back into nil. Instead, it decoded it as a non-nil zero-value element.

For types.Commit.Precommits, that is consensus-critical because the list is positional. A missing precommit must remain nil; turning it into a zero-value CommitSig makes the reconstructed commit invalid, which is why the next proposal failed with wrong LastCommit.

The fix makes generated unmarshal match the reflect codec again: empty entries decode to nil, non-empty entries stay on the generated fast path, and anyDepth is preserved.

Why This Fix

Commit.Precommits is positional and uses amino:"nil_elements". Losing nil entries or changing their decode semantics is not just cosmetic; it changes the meaning of the commit.

The final implementation keeps genproto2 behavior aligned with the reflect codec while preserving the generated fast path and existing depth-guard semantics.

Signed-off-by: D4ryl00 <d4ryl00@gmail.com>
@Gno2D2
Copy link
Copy Markdown
Collaborator

Gno2D2 commented Apr 22, 2026

🛠 PR Checks Summary

All Automated Checks passed. ✅

Manual Checks (for Reviewers):
  • IGNORE the bot requirements for this PR (force green CI check)
  • The pull request description provides enough details
Read More

🤖 This bot helps streamline PR reviews by verifying automated checks and providing guidance for contributors and reviewers.

✅ Automated Checks (for Contributors):

🟢 Maintainers must be able to edit this pull request (more info)
🟢 Pending initial approval by a review team member, or review from tech-staff

☑️ Contributor Actions:
  1. Fix any issues flagged by automated checks.
  2. Follow the Contributor Checklist to ensure your PR is ready for review.
    • Add new tests, or document why they are unnecessary.
    • Provide clear examples/screenshots, if necessary.
    • Update documentation, if required.
    • Ensure no breaking changes, or include BREAKING CHANGE notes.
    • Link related issues/PRs, where applicable.
☑️ Reviewer Actions:
  1. Complete manual checks for the PR, including the guidelines and additional checks if applicable.
📚 Resources:
Debug
Automated Checks
Maintainers must be able to edit this pull request (more info)

If

🟢 Condition met
└── 🟢 And
    ├── 🟢 The base branch matches this pattern: ^master$
    └── 🟢 The pull request was created from a fork (head branch repo: D4ryl00/gno)

Then

🟢 Requirement satisfied
└── 🟢 Maintainer can modify this pull request

Pending initial approval by a review team member, or review from tech-staff

If

🟢 Condition met
└── 🟢 And
    ├── 🟢 The base branch matches this pattern: ^master$
    └── 🟢 Not (🔴 Pull request author is a member of the team: tech-staff)

Then

🟢 Requirement satisfied
└── 🟢 If
    ├── 🟢 Condition
    │   └── 🟢 Or
    │       ├── 🟢 User jefft0 already reviewed PR 5569 with state APPROVED
    │       ├── 🟢 At least 1 user(s) of the team tech-staff reviewed pull request
    │       └── 🔴 This pull request is a draft
    └── 🟢 Then
        └── 🟢 Not (🔴 This label is applied to pull request: review/triage-pending)

Manual Checks
**IGNORE** the bot requirements for this PR (force green CI check)

If

🟢 Condition met
└── 🟢 On every pull request

Can be checked by

  • Any user with comment edit permission
The pull request description provides enough details

If

🟢 Condition met
└── 🟢 And
    ├── 🟢 Not (🔴 Pull request author is a member of the team: core-contributors)
    └── 🟢 Not (🔴 Pull request author is user: dependabot[bot])

Can be checked by

  • team core-contributors

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 22, 2026

Codecov Report

❌ Patch coverage is 88.39779% with 42 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
tm2/pkg/amino/genproto2/gen_unmarshal.go 70.00% 20 Missing and 4 partials ⚠️
tm2/pkg/amino/tests/pb3_gen.go 95.48% 8 Missing and 4 partials ⚠️
tm2/pkg/bft/types/pb3_gen.go 62.50% 4 Missing and 2 partials ⚠️

📢 Thoughts on this report? Let us know!

@D4ryl00 D4ryl00 marked this pull request as ready for review April 22, 2026 08:53
@Gno2D2 Gno2D2 added the review/triage-pending PRs opened by external contributors that are waiting for the 1st review label Apr 22, 2026
@D4ryl00 D4ryl00 changed the title fix: unmarshal amino nil pointers fix(tm2/amino): preserve nil_elements in genproto2 Apr 22, 2026
Copy link
Copy Markdown
Contributor

@jefft0 jefft0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR has tests for the fix described in the description. CI checks pass. Ready for core devs to review. Urgent fix for the stability of the chain.

@Gno2D2 Gno2D2 removed the review/triage-pending PRs opened by external contributors that are waiting for the 1st review label Apr 22, 2026
@jefft0 jefft0 moved this to Other in review in 🤝🏻 Partner: Berty Apr 22, 2026
@aeddi aeddi added the a/gnops DevOps, Valopers, NetOps, Infra, Monitoring, Coordination team label Apr 22, 2026
Comment thread tm2/pkg/amino/genproto2/gen_unmarshal.go Outdated
Signed-off-by: D4ryl00 <d4ryl00@gmail.com>
@jaekwon
Copy link
Copy Markdown
Contributor

jaekwon commented Apr 24, 2026

taking a look now

@jaekwon
Copy link
Copy Markdown
Contributor

jaekwon commented Apr 24, 2026

Added alt with more fixes: #5590

@jaekwon jaekwon closed this Apr 24, 2026
@github-project-automation github-project-automation Bot moved this from In Progress to Done in 💪 Bounties & Worx Apr 24, 2026
@github-project-automation github-project-automation Bot moved this from Other in review to Done in 🤝🏻 Partner: Berty Apr 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

a/gnops DevOps, Valopers, NetOps, Infra, Monitoring, Coordination team amino Issues and PRs related to amino 📦 🌐 tendermint v2 Issues or PRs tm2 related

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

7 participants